﻿using System;
using Microsoft.Win32;

namespace Just4Devs.Vsirc.Addin
{
    public class VsircServerConfiguration
    {
        private static VsircServerConfiguration _instance;
        private static object _syncLock = new object();

        public static VsircServerConfiguration GetInstance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                    {
                        _instance = new VsircServerConfiguration();
                    }
                }
            }

            return _instance;
        }

        public string Server { get; set; }

        public string OriginalNick { get; set; }

        public string RealName { get; set; }

        public string FirstChannel { get; set; }

        public int Port { get; set; }

        public void ReadIrcServerConfiguration()
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software", true);
            key = key.OpenSubKey(@"AnAppADay\JediVSIRC");
            try
            {
                Server = key.GetValue("server", "Atlanta.ga.us.dal.net") as string;

                try
                {
                    Port = Int32.Parse(key.GetValue("port", "6667") as string);
                }
                catch
                {
                    Port = 6667;
                }

                OriginalNick = key.GetValue("nick", "cokeijo") as string;
                RealName = key.GetValue("realName", "MarcosBrigante") as string;
                FirstChannel = key.GetValue("channel", "#CokeTest") as string;
                key.Close();
            }
            catch
            {
                //_server will be null, fall through
            }
        }

    }
}
